import { getLineCodeList, getTeamLeaderCodeList } from "@/api/mesScheduling/mesTeam";
import { checkStr } from "@/utils/judge";
import url from "@/axios/url";
const { messerviceUrl,mesUrl } = url();
import excelUpload from "@/components/excel-upload/excelUpload";
// 列表头按钮配置
export const operateList = {
  data() {
    const _this = this;
    return {
      operateList: [
        {
          name: $i18n.t("common.add"),
          type: "primary",
          icon: "el-icon-circle-plus-outline",
          handleName: "add", //点击时返回的标识
        },

        {
          name: $i18n.t("common.delete"),
          type: "danger",
          icon: "el-icon-delete",
          handleName: "deleteBatch", //点击时返回的标识
          isMultiple: true,
        },
        {
          // 导入文件
          render: (h, scope) => {
            // scope列表上选择的数据
            const uploadUrl = `${mesUrl}mesTeam/import`;
            return (
              <excelUpload
                action={uploadUrl}
                on={{
                  handleUploadError: (err) => {
                    // 失败的回调
                    console.log(err);
                  },
                  handleUploadSuccess: (res) => {
                    _this.$refs.eleTable.handleReset();
                    //成功 的回调
                  },
                }}
              />
            );
          },
        },
        {
          name: $i18n.t("common.downloadTemplate"),
          type: "success",
          icon: "el-icon-download",
          handleName: "exportExcel", //点击时返回的标识
        },
      ],
    };
  },
};
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  data() {
    const self = this;
    return {
      searchDialog: {
        inline: true,
        formDesc: {
          teamCode: {
            type: "input",
            label: $i18n.t("mesTeam.teamCode"),
          },
          teamName: {
            type: "input",
            label: $i18n.t("mesTeam.teamName"),
          },
          lineCode: {
            type: "select",
            label: $i18n.t("mesTeam.line"),
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: self.$store.getters.factoryCode,
                level: 5,
              };
              const list = await getLineCodeList(params);
              return list.data.result;
            },
          },
          // teamLeaderCode: {
          //   type: "select",
          //   label: "班组长编码",
          //   type: 'select',
          //   prop: {
          //     value: "value",
          //     text: "description",
          //   },
          //   options: async (data) => {
          //     const list = await getTeamLeaderCodeList()
          //     return list.data.result
          //   },
          // },
        },
      },
    };
  },
};
var validatePass = (rule, value, callback) => {
  setTimeout(() => {
    if (!checkStr(value, "english-number-")) {
      callback(new Error($i18n.t("mesTeam.rule11")));
    } else {
      callback();
    }
  }, 100);
};
// 新增/删除表单配置

export const formDescDialogMinxin = {
  data() {
    const self = this;
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        rules: {
          teamCode: [{ validator: validatePass, trigger: ["change", "blur"] }],
        },
        formDesc: {
          teamCode: {
            type: "input",
            label: $i18n.t("mesTeam.teamCode"),
            layout: 12,
            disabled: (data) => {
              return !!data.codeStrategy || !!data.id;
            },
            // required: true,
          },
          teamName: {
            type: "input",
            label: $i18n.t("mesTeam.teamName"),
            layout: 12,
            required: true,
          },
          lineCode: {
            type: "select",
            label: $i18n.t("mesTeam.line"),
            layout: 12,
            required: true,
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async () => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 5,
              };
              const list = await getLineCodeList(params);
              const data = list.data.result;
              self.lineCodeList = data;
              return data;
            },
            on: {
              change: (val) => {
                console.log(val);
                const findItem =
                  self.lineCodeList.find((item) => item.modelingCode == val) ||
                  {};
                self.$set(
                  self.formDataDialog,
                  "lineName",
                  findItem.modelingName || ""
                );
                // this.$set(this.formDataDialog, "teamLeaderName", data[0].nickName||"");
              },
            },
          },
          // lineName: {

          //   // type: "input",
          //   // label: "线体名称",
          //   // layout: 12,
          //   // required: true,
          //   // disabled: true,
          // },
          teamLeaderCode: {
            type: "select",
            label: $i18n.t("mesTeam.teamLeaderCode"),
            layout: 12,
            required: false,
            prop: {
              value: "value",
              text: "description",
            },
            // options: async () => {
            //   const list = await getTeamLeaderCodeList();
            //   const data = list.data.result;
            //   console.log(self, data);
            //   self.userCodeList = data;
            //   return data;
            // },
            on: {
              change: (val) => {
                console.log(val);
                const findItem =
                  self.userCodeList.find((item) => item.value == val) || {};
                self.$set(
                  self.formDataDialog,
                  "teamLeaderName",
                  findItem.description || ""
                );
              },
            },
          },
          teamLeaderName: {
            type: "input",
            label: $i18n.t("mesTeam.teamLeaderName"),
            layout: 12,
            // required: true,
            disabled: true,
          },
          // teamLeaderName: {
          //   // type: "input",
          //   // label: "班组长名称",
          //   // layout: 12,
          //   // required: false,
          //   // disabled: true,
          // },
          planPostQuantity: {
            type: "number",
            label: $i18n.t("mesTeam.planPostQuantity"),
            layout: 12,
            attrs: {
              min: 0,
            },
            required: false,
          },
          actualPostQuantity: {
            type: "number",
            label: $i18n.t("mesTeam.actualPostQuantity"),
            attrs: {
              min: 0,
            },
            layout: 12,
            required: false,
          },
          remark: {
            type: "textarea",
            label: $i18n.t("common.remark"),
            layout: 24,
            required: false,
          },
        },
      },
    };
  },
};
